<template>
  <a-button :loading="loading" @click="onClick" :style="buttonStyle">
    <a-icon v-if="prefixIcon" :type="prefixIcon"/>
    <span :style="{marginLeft:prefixIcon||suffixIcon?'4px':'0'}"> {{ btnContent }}</span>
    <a-icon v-if="suffixIcon" :type="suffixIcon"/>
  </a-button>
</template>

<script>
  export default {
    name: 'BButton',
    props: {
      loading: {
        type: Boolean,
        default: false
      },
      block: {
        type: Boolean,
        default: false
      },
      type: {
        type: String,
        default: 'primary'
      },
      size: {
        type: String,
        default: 'normal'
      },
      shape: {
        type: String,
        default: '4px'
      },
      /**
       * 按钮类型，次要，线框，主要
       */
      ghost: {
        type: String,
        default: 'main'
      },
      btnContent: {
        type: String,
        default: ''
      },
      prefixIcon: {
        type: String,
        default: ''
      },
      suffixIcon: {
        type: String,
        default: ''
      }
    },
    data () {
      return {
        buttonStyle: 'height: auto;',
        defaultColor: {}
      }
    },
    mounted () {
      this.initStyle()
    },
    methods: {
      initColor () {
        switch (this.type) {
          case 'primary':
            this.defaultColor = {
              main: '#1890FF',
              minor: '#A5D6FF',
              least: '#E5F7FF'
            }
            break
          case 'danger':
            this.defaultColor = {
              main: '#FF9EA1',
              minor: '#FC4F54',
              least: '#FFF1F0'
            }
            break
          case 'warning':
            this.defaultColor = {
              main: '#FAAD13',
              minor: '#FFE4AF',
              least: '#FFFBE7'
            }
            break
          case 'success':
            this.defaultColor = {
              main: '#52C41A',
              minor: '#A1D985',
              least: '#F6FFEE'
            }
            break
          case 'default':
            this.defaultColor = {
              main: '#D9D9D9',
              minor: '#8C8C8C',
              least: 'white'
            }
        }
      },
      initStyle () {
        this.initColor()
        this.initSize()
        this.initShape()
        this.initBlock()
        this.initGhost()
      },
      initGhost () {
        switch (this.ghost) {
          case 'main':
            this.buttonStyle += 'background:' + this.defaultColor.main + ';color:white;'
            break
          case 'minor':
            this.buttonStyle += 'background:' + this.defaultColor.minor + ';color:;' + this.defaultColor.least + ';border: 1px solid ' + this.defaultColor.main
            break
          case 'least':
            this.buttonStyle += 'background:white; color:' + this.defaultColor.minor + ';border: 1px solid ' + this.defaultColor.main
            break
          case 'default':
            this.buttonStyle += 'background:white; color:' + this.defaultColor.minor + ';border: 1px solid ' + this.defaultColor.main
            break
        }
      },
      initBlock () {
        if (this.block) {
          this.buttonStyle += 'width:100%;'
        }
      },
      initShape () {
        this.buttonStyle += 'border-radius:' + this.shape + ';'
      },
      initSize () {
        switch (this.size) {
          case 'large':
            this.buttonStyle += 'padding:11px 16px;font-size:14px;'
            break
          case 'mini':
            this.buttonStyle += 'padding:2px 16px;font-size:14px;'
            break
          case 'small':
            this.buttonStyle += 'padding:0 6px;font-size:12px;'
            break
          case 'normal':
            this.buttonStyle += 'padding:5px 16px;font-size:14px;'
            break
        }
      },
      onClick () {
        this.$emit('click')
      }
    }
  }
</script>

<style scoped>

</style>
